Ext.ns('journal.home');

journal.home.PropertyDialogForm = Ext.extend(Ext.form.FormPanel, (function() {
    return {
        // defaults - can be changed from outside
        border : false,
        frame : true,
        labelWidth : 80,
        constructor : function(config) {
            config = config || {};
            config.listeners = config.listeners || {};
            journal.home.PropertyDialogForm.superclass.constructor.call(this, config);
        },
        initComponent : function() {

            // hard coded - cannot be changed from outside
            var config = {
                defaultType : 'textfield',
                autoHeight : true,
                autoWidth : true,
                monitorValid : true,
                autoScroll : true,
                defaults : {
                    style : 'margin: 3px 0 0 0'
                },
                items : [ {
                    name : 'nodeTitle',
                    fieldLabel : 'Node Title',
                    iconCls : 'icon-connect',
                    anchor : '100%',
                    value : this.node.text,
                    disabled : true
                }, {
                    xtype : 'journal.ui.LineSeparator'
                }, {
                    xtype : 'journal.ui.ValueField',
                    fieldLabel : 'Type of Node',
                    value : this.node.isLeaf() ? 'Entry' : 'Branch'
                }, {
                    xtype : 'journal.ui.LineSeparator'
                }, {
                    xtype : 'journal.ui.ValueField',
                    fieldLabel : 'Logical Path',
                    value : this.node.getPath()
                }, {
                    xtype : 'journal.ui.ValueField',
                    fieldLabel : 'Path',
                    id : 'friendlyPath'
                }, {
                    xtype : 'journal.ui.ValueField',
                    fieldLabel : 'Size',
                    id : 'size',
                    value : ''
                }, {
                    xtype : 'journal.ui.LineSeparator'
                }, {
                    xtype : 'journal.ui.ValueField',
                    fieldLabel : 'Created',
                    id : 'created',
                    value : ''
                }, {
                    xtype : 'journal.ui.ValueField',
                    fieldLabel : 'Modified',
                    id : 'modified'
                } ],
                buttons : [ {
                    text : 'Ok',
                    scope : this,
                    handler : function() {
                        this.ownerCt.close();
                    }
                } ]
            }; // eo config object

            this.on('render', function() {
                Ext.Ajax.request({
                    url : 'home',
                    params : {
                        action : 'getNodeProperty',
                        nodeId : this.node.id
                    },
                    success : function(response, opts) {
                        var respObj = Ext.util.JSON.decode(response.responseText);
                        if (respObj.success) {
                            this.findById('size').update(respObj.size);
                            this.findById('created').update(respObj.created);
                            this.findById('modified').update(respObj.modified);
                            this.findById('friendlyPath').update(respObj.path);
                        } else {
                            journal.Utility.doStandardError(respObj);
                        }
                    }.createDelegate(this),
                    failure : function(response, opts) {
                        //Note: Will arrive here on System Error only.
                    }
                });
            });

            // apply config
            Ext.apply(this, Ext.apply(this.initialConfig, config));

            // call parent
            journal.home.PropertyDialogForm.superclass.initComponent.apply(this, arguments);

        }, // eo function initComponent

        /** Form override */
        onRender : function() {
            // call parent
            journal.home.PropertyDialogForm.superclass.onRender.apply(this, arguments);
            // set wait message target
            this.getForm().waitMsgTarget = this.getEl();
        } // eo function onRender
    };
})()); // eo extend

// register xtype
Ext.reg('journal.home.PropertyDialogForm', journal.home.PropertyDialogForm);